﻿using System;
using Microsoft.Xna.Framework;

namespace Terraria
{
	// Token: 0x02000009 RID: 9
	public class CombatText
	{
		// Token: 0x17000022 RID: 34
		// (get) Token: 0x06000094 RID: 148 RVA: 0x00006572 File Offset: 0x00004772
		public static float TargetScale
		{
			get
			{
				return Main.UIScale / (Main.GameViewMatrix.Zoom.X / Main.ForcedMinimumZoom);
			}
		}

		// Token: 0x06000095 RID: 149 RVA: 0x0000658F File Offset: 0x0000478F
		public static int NewText(Rectangle location, Color color, int amount, bool dramatic = false, bool dot = false)
		{
			return CombatText.NewText(location, color, amount.ToString(), dramatic, dot);
		}

		// Token: 0x06000096 RID: 150 RVA: 0x0002AA8C File Offset: 0x00028C8C
		public static int NewText(Rectangle location, Color color, string text, bool dramatic = false, bool dot = false)
		{
			if (Main.netMode == 2)
			{
				return 100;
			}
			for (int i = 0; i < 100; i++)
			{
				if (!Main.combatText[i].active)
				{
					int num = 0;
					if (dramatic)
					{
						num = 1;
					}
					Vector2 vector = Main.fontCombatText[num].MeasureString(text);
					Main.combatText[i].alpha = 1f;
					Main.combatText[i].alphaDir = -1;
					Main.combatText[i].active = true;
					Main.combatText[i].scale = 0f;
					Main.combatText[i].rotation = 0f;
					Main.combatText[i].position.X = (float)location.X + (float)location.Width * 0.5f - vector.X * 0.5f;
					Main.combatText[i].position.Y = (float)location.Y + (float)location.Height * 0.25f - vector.Y * 0.5f;
					CombatText combatText = Main.combatText[i];
					combatText.position.X = combatText.position.X + (float)Main.rand.Next(-(int)((double)location.Width * 0.5), (int)((double)location.Width * 0.5) + 1);
					CombatText combatText2 = Main.combatText[i];
					combatText2.position.Y = combatText2.position.Y + (float)Main.rand.Next(-(int)((double)location.Height * 0.5), (int)((double)location.Height * 0.5) + 1);
					Main.combatText[i].color = color;
					Main.combatText[i].text = text;
					Main.combatText[i].velocity.Y = -7f;
					if (Main.player[Main.myPlayer].gravDir == -1f)
					{
						CombatText combatText3 = Main.combatText[i];
						combatText3.velocity.Y = combatText3.velocity.Y * -1f;
						Main.combatText[i].position.Y = (float)location.Y + (float)location.Height * 0.75f + vector.Y * 0.5f;
					}
					Main.combatText[i].lifeTime = 60;
					Main.combatText[i].crit = dramatic;
					Main.combatText[i].dot = dot;
					if (dramatic)
					{
						Main.combatText[i].text = text;
						Main.combatText[i].lifeTime *= 2;
						CombatText combatText4 = Main.combatText[i];
						combatText4.velocity.Y = combatText4.velocity.Y * 2f;
						Main.combatText[i].velocity.X = (float)Main.rand.Next(-25, 26) * 0.05f;
						Main.combatText[i].rotation = (float)(Main.combatText[i].lifeTime / 2) * 0.002f;
						if (Main.combatText[i].velocity.X < 0f)
						{
							Main.combatText[i].rotation *= -1f;
						}
					}
					if (dot)
					{
						Main.combatText[i].velocity.Y = -4f;
						Main.combatText[i].lifeTime = 40;
					}
					return i;
				}
			}
			return 100;
		}

		// Token: 0x06000097 RID: 151 RVA: 0x0002ADF0 File Offset: 0x00028FF0
		public static void clearAll()
		{
			for (int i = 0; i < 100; i++)
			{
				Main.combatText[i].active = false;
			}
		}

		// Token: 0x06000098 RID: 152 RVA: 0x0002AE18 File Offset: 0x00029018
		public void Update()
		{
			if (this.active)
			{
				float targetScale = CombatText.TargetScale;
				this.alpha += (float)this.alphaDir * 0.05f;
				if ((double)this.alpha <= 0.6)
				{
					this.alphaDir = 1;
				}
				if (this.alpha >= 1f)
				{
					this.alpha = 1f;
					this.alphaDir = -1;
				}
				if (this.dot)
				{
					this.velocity.Y = this.velocity.Y + 0.15f;
				}
				else
				{
					this.velocity.Y = this.velocity.Y * 0.92f;
					if (this.crit)
					{
						this.velocity.Y = this.velocity.Y * 0.92f;
					}
				}
				this.velocity.X = this.velocity.X * 0.93f;
				this.position += this.velocity;
				this.lifeTime--;
				if (this.lifeTime <= 0)
				{
					this.scale -= 0.1f * targetScale;
					if ((double)this.scale < 0.1)
					{
						this.active = false;
					}
					this.lifeTime = 0;
					if (this.crit)
					{
						this.alphaDir = -1;
						this.scale += 0.07f * targetScale;
						return;
					}
				}
				else
				{
					if (this.crit)
					{
						if (this.velocity.X < 0f)
						{
							this.rotation += 0.001f;
						}
						else
						{
							this.rotation -= 0.001f;
						}
					}
					if (this.dot)
					{
						this.scale += 0.5f * targetScale;
						if ((double)this.scale > 0.8 * (double)targetScale)
						{
							this.scale = 0.8f * targetScale;
							return;
						}
					}
					else
					{
						if (this.scale < targetScale)
						{
							this.scale += 0.1f * targetScale;
						}
						if (this.scale > targetScale)
						{
							this.scale = targetScale;
						}
					}
				}
			}
		}

		// Token: 0x06000099 RID: 153 RVA: 0x0002B040 File Offset: 0x00029240
		public static void UpdateCombatText()
		{
			for (int i = 0; i < 100; i++)
			{
				if (Main.combatText[i].active)
				{
					Main.combatText[i].Update();
				}
			}
		}

		// Token: 0x04000056 RID: 86
		public static readonly Color DamagedFriendly = new Color(255, 80, 90, 255);

		// Token: 0x04000057 RID: 87
		public static readonly Color DamagedFriendlyCrit = new Color(255, 100, 30, 255);

		// Token: 0x04000058 RID: 88
		public static readonly Color DamagedHostile = new Color(255, 160, 80, 255);

		// Token: 0x04000059 RID: 89
		public static readonly Color DamagedHostileCrit = new Color(255, 100, 30, 255);

		// Token: 0x0400005A RID: 90
		public static readonly Color OthersDamagedHostile = CombatText.DamagedHostile * 0.4f;

		// Token: 0x0400005B RID: 91
		public static readonly Color OthersDamagedHostileCrit = CombatText.DamagedHostileCrit * 0.4f;

		// Token: 0x0400005C RID: 92
		public static readonly Color HealLife = new Color(100, 255, 100, 255);

		// Token: 0x0400005D RID: 93
		public static readonly Color HealMana = new Color(100, 100, 255, 255);

		// Token: 0x0400005E RID: 94
		public static readonly Color LifeRegen = new Color(255, 60, 70, 255);

		// Token: 0x0400005F RID: 95
		public static readonly Color LifeRegenNegative = new Color(255, 140, 40, 255);

		// Token: 0x04000060 RID: 96
		public Vector2 position;

		// Token: 0x04000061 RID: 97
		public Vector2 velocity;

		// Token: 0x04000062 RID: 98
		public float alpha;

		// Token: 0x04000063 RID: 99
		public int alphaDir = 1;

		// Token: 0x04000064 RID: 100
		public string text;

		// Token: 0x04000065 RID: 101
		public float scale = 1f;

		// Token: 0x04000066 RID: 102
		public float rotation;

		// Token: 0x04000067 RID: 103
		public Color color;

		// Token: 0x04000068 RID: 104
		public bool active;

		// Token: 0x04000069 RID: 105
		public int lifeTime;

		// Token: 0x0400006A RID: 106
		public bool crit;

		// Token: 0x0400006B RID: 107
		public bool dot;
	}
}
